package edu.yourl.presenter;

import java.util.ArrayList;
import java.util.List;

import edu.yourl.domain.Domain;
import edu.yourl.domain.Favoritable;
import edu.yourl.domain.Gossip;
import edu.yourl.domain.Url;
import edu.yourl.persistence.IFavoritableRepository;
import edu.yourl.persistence.IGossipRepository;
import edu.yourl.persistence.IUserRepository;

public class SearchPresenter implements ISearchPresenter {

	private IFavoritableRepository favoritableRepository;
	private IUserRepository userRepository;
	private IGossipRepository gossipRepository;

	@Override
	public List<? extends Favoritable> searchFavoritables(String search) {
		List<Favoritable> toReturn = new ArrayList<Favoritable>(this.userRepository.searchUsers(search));
		toReturn.addAll(favoritableRepository.findAllFavoritablesByName(Url.class, search));
		toReturn.addAll(favoritableRepository.findAllFavoritablesByName(Domain.class, search));
		return toReturn;
	}

	@Override
	public List<Gossip> searchGossips(String search) {
		return this.gossipRepository.search(search);
	}

	public void setUserRepository(IUserRepository userRepository) {
		this.userRepository = userRepository;
	}

	
	public void setGossipRepository(IGossipRepository gossipRepository) {
		this.gossipRepository = gossipRepository;
	}

	public void setFavoritableRepository(
			IFavoritableRepository favoritableRepository) {
		this.favoritableRepository = favoritableRepository;
	}


}
